﻿
var aValue = false;
var bValue = false;


function ajaxRequest() {
    var activexmodes = ["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE
    if (window.ActiveXObject) { //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
        for (var i = 0; i < activexmodes.length; i++) {
            try {
                aValue = true;
                bValue = false;
                return new ActiveXObject(activexmodes[i])
            }
            catch (e) {
                //suppress error
            }
        }
    }
    else if (window.XMLHttpRequest) { // if Mozilla, Safari etc
        bValue = true;
        aValue = false;
        return new XMLHttpRequest()
    }
    else
        return false
}


//ajaxRequest();



function InternalApi() {

    this.sendRequest = sendRequest;
    ajaxRequest();
    this.aValue = aValue;
    this.bValue = bValue;

}


function sendRequest(CoursesID, CurrentData, ScoID) {

    var myXml = null;
    var activexmodes = ["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"];

    if (this.aValue) {
        for (var i = 0; i < activexmodes.length; i++) {
            try {
               
                myXml =  new ActiveXObject(activexmodes[i])
            }
            catch (e) {
                //suppress error
            }
        }
    }
    else if (this.bValue) {
        myXml = new XMLHttpRequest();
    }
    else
        return;



    

    myXml.onreadystatechange = function () {
        if (myXml.readyState == 4) {
            if (myXml.status == 200) {


                if (myXml.responseText.indexOf("false") != -1) {
                    //alert (myXml.responseText);
                    // server error no login user found
                    return;
                }

            }
            else {
                //client error , no internet connection
                return;

            }
        }

    }

    

    myXml.open("POST", "./addRegCourseData.ashx", true);

    var params = "CoursesID=" + CoursesID.toString() + "&ScoID=" + ScoID.toString() +
                 "&CurrentData=" + CurrentData.toString();

    //alert (params);

    myXml.setRequestHeader("Content-type", "application/x-www-form-urlencoded")

    myXml.send(params);


}


var inApi = new InternalApi();

